Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
babel-plugin-transform-class-properties
Advanced tools
This plugin transforms static class properties as well as properties declared with the property initializer syntax
The babel-plugin-transform-class-properties package is a Babel plugin that allows you to use class properties in your JavaScript code. This plugin transforms class properties to be compatible with older JavaScript environments that do not support this feature natively.
Public Class Fields
This feature allows you to define public class fields directly within the class body. The plugin transforms this syntax to be compatible with older JavaScript environments.
class MyClass {
myField = 'Hello, world!';
}
Static Class Fields
This feature allows you to define static class fields directly within the class body. Static fields are shared among all instances of the class. The plugin ensures this syntax works in environments that do not support it natively.
class MyClass {
static myStaticField = 'Hello, static world!';
}
Instance Property Initialization
This feature allows you to initialize instance properties directly within the class body, making the code more concise and readable. The plugin transforms this syntax to be compatible with older JavaScript environments.
class MyClass {
myField = 'Hello, world!';
constructor() {
console.log(this.myField);
}
}
The babel-plugin-transform-es2015-classes package transforms ES2015 class syntax to ES5. While it does not specifically focus on class properties, it is often used in conjunction with other plugins to achieve similar functionality.
This plugin transforms es2015 static class properties as well as properties declared with the es2016 property initializer syntax.
Below is a class with four class properties which will be transformed.
class Bork {
//Property initializer syntax
instanceProperty = "bork";
boundFunction = () => {
return this.instanceProperty;
}
//Static class properties
static staticProperty = "babelIsCool";
static staticFunction = function() {
return Bork.staticProperty;
}
}
let myBork = new Bork;
//Property initializers are not on the prototype.
console.log(myBork.prototype.boundFunction); // > undefined
//Bound functions are bound to the class instance.
console.log(myBork.boundFunction.call(undefined)); // > "bork"
//Static function exists on the class.
console.log(Bork.staticFunction()); // > "babelIsCool"
npm install --save-dev babel-plugin-transform-class-properties
.babelrc
(Recommended).babelrc
// without options
{
"plugins": ["transform-class-properties"]
}
// with options
{
"plugins": [
["transform-class-properties", { "spec": true }]
]
}
babel --plugins transform-class-properties script.js
require("babel-core").transform("code", {
plugins: ["transform-class-properties"]
});
spec
boolean
, defaults to false
.
Class properties are compiled to use Object.defineProperty
. Static fields are now defined even if they are not initialized.
FAQs
This plugin transforms static class properties as well as properties declared with the property initializer syntax
The npm package babel-plugin-transform-class-properties receives a total of 0 weekly downloads. As such, babel-plugin-transform-class-properties popularity was classified as not popular.
We found that babel-plugin-transform-class-properties demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.